package com.dw.etl.core.controller;

import javax.servlet.http.HttpServletRequest;

import com.dw.etl.common.base.BaseException;
import com.dw.etl.core.bean.vo.EtlIndexShowVO;
import com.dw.etl.core.bean.vo.EtlIndexSqlVO;
import org.springframework.beans.factory.annotation.Autowired;
import  com.dw.etl.common.base.BaseResult;
import  com.dw.etl.common.constant.CommonResultConstant;
import com.dw.etl.core.api.BaseIndexConfService;
import com.dw.etl.core.bean.model.BaseIndexConf;
import org.springframework.util.StringUtils;
import  com.dw.etl.common.vo.PaginationVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * baseIndexConf控制器
 * Created by hozeData on 2021/06/21.
 */
@RestController
@RequestMapping("/hoze/baseIndexConf/")
@Api(tags="指标SQL配置")
public class BaseIndexConfController {

    @Autowired
    BaseIndexConfService baseIndexConfService;

    @ApiOperation(value="分页查询")
    @RequestMapping(value="findByPage", method=RequestMethod.POST)
    public BaseResult findByPage(@RequestBody BaseIndexConf baseIndexConf, Integer pageNum, Integer pageSize) {
        PaginationVO<BaseIndexConf> pageVO = baseIndexConfService.findPageByModel(baseIndexConf, pageNum, pageSize);
        return new BaseResult(CommonResultConstant.SUCCESS, pageVO);
    }

    @ApiOperation(value="根据指标主键查询")
    @RequestMapping(value="getByIndex", method=RequestMethod.GET)
    public BaseResult getByIndex(String pkIndex) {
        EtlIndexShowVO pageVO = baseIndexConfService.getByIndex(pkIndex);
        return new BaseResult(CommonResultConstant.SUCCESS, pageVO);
    }

    @ApiOperation(value="保存")
    @ApiImplicitParam(name="EtlIndexSqlVO", value="实体", paramType="body", required=true, dataType="EtlIndexSqlVO")
    @RequestMapping(value="save", method=RequestMethod.POST)
    public BaseResult save(@RequestBody EtlIndexSqlVO vo)  {
        baseIndexConfService.save(vo);
        return new BaseResult(CommonResultConstant.SUCCESS, null);
    }

    @ApiOperation(value="详情")
    @ApiImplicitParam(name="pk", value="主键", paramType="query", required=true, dataType="String")
    @RequestMapping(value="getById", method=RequestMethod.GET)
    public BaseResult getById(String pk, HttpServletRequest request) throws BaseException {
        if(StringUtils.isEmpty(pk)){
            throw new BaseException("请选择要编辑的项");
        }
        BaseIndexConf baseIndexConf = baseIndexConfService.getById(pk);
        return new BaseResult(CommonResultConstant.SUCCESS, baseIndexConf);
    }

    @ApiOperation(value="修改")
    @ApiImplicitParam(name="baseIndexConf", value="实体", paramType="body", required=true, dataType="BaseIndexConf")
    @RequestMapping(value="update", method=RequestMethod.POST)
    public BaseResult update(@RequestBody BaseIndexConf baseIndexConf, HttpServletRequest request)  {
        int num = baseIndexConfService.updateByIdSelective(baseIndexConf);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }

    @ApiOperation(value="根据主键删除")
    @ApiImplicitParam(name="pk", value="主键", paramType="query", required=true, dataType="String")
    @RequestMapping(value="delete", method=RequestMethod.GET)
    public BaseResult delete(String pk, HttpServletRequest request) throws BaseException {
        if(StringUtils.isEmpty(pk)){
            throw new BaseException("请选择要删除的项");
        }
        int num = baseIndexConfService.deleteById(pk);
        return new BaseResult(CommonResultConstant.SUCCESS, num);
    }



}
